******
*DLW (2012) MATA PROGRAM
******
*clear mata
mata: 
mata set matastrict off
void GMM_DLW(todo,betas,crit,g,H)
{
	PHI=st_data(.,("phi")) 
    PHI_LAG=st_data(.,("phi_lag"))
    Z=st_data(.,("const","l_lag","k"))
    X=st_data(.,("const","l","k","m"))
    X_lag=st_data(.,("const","l_lag","k_lag","m_lag"))
    Y=st_data(.,("va"))
    C=st_data(.,("const"))

	OMEGA=PHI-X*betas'
	OMEGA_lag=PHI_LAG-X_lag*betas'
	OMEGA_lag_pol=(C,OMEGA_lag)
	g_b = invsym(OMEGA_lag_pol'OMEGA_lag_pol)*OMEGA_lag_pol'OMEGA
	XI=OMEGA-OMEGA_lag_pol*g_b
	crit=(Z'XI)'(Z'XI)
}

void DLW()
	{
S=optimize_init()
optimize_init_evaluator(S, &GMM_DLW())
optimize_init_evaluatortype(S,"d0")
optimize_init_technique(S, "nm")
optimize_init_nmsimplexdeltas(S, 0.1)
optimize_init_which(S,"min")
optimize_init_params(S,(0,`=blols',`=bkols',`=bmols'))
p=optimize(S)
p
st_matrix("beta_dlw",p)
}
end